1893B - Neutral Tonality - CodeForces Solution


constructive algorithms greedy sortings two pointers

Please click on ads to support us..

C++ Code:

/*
 *أَمْ حَسِبْتُمْ أَن تَدْخُلُوا الْجَنَّةَ وَلَمَّا يَأْتِكُم مَّثَلُ الَّذِينَ خَلَوْا مِن قَبْلِكُم ۖ مَّسَّتْهُمُ الْبَأْسَاءُ وَالضَّرَّاءُ وَزُلْزِلُوا حَتَّىٰ يَقُولَ الرَّسُولُ وَالَّذِينَ آمَنُوا مَعَهُ مَتَىٰ نَصْرُ اللَّهِ ۗ أَلَا إِنَّ نَصْرَ اللَّهِ قَرِيبٌ (214)
 *by : @Tesla .
 */
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define rall(n) n.rbegin(), n.rend()
#define all(n) n.begin(), n.end()
const int MOD = 1e9 + 7;

int32_t main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T ; cin >> T ;
	while(T--){
		int N , M ; cin >> N >> M ;
		vector<int>A(N),B(M),ans(N + M);
		for(int i = 0 ; i < N ; i ++) cin >> A[i] ;
		for(int i = 0 ; i < M ; i ++) cin >> B[i] ;
		sort(rall(B)) ;
		merge(all(A),all(B),ans.begin(),greater<int>());
		for(int i = 0 ; i < N + M ; i ++) cout << ans[i] << " \n"[i + 1 == N + M] ;
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

363D - Renting Bikes
1198D - Rectangle Painting 1
1023B - Pair of Toys
1725A - Accumulation of Dominoes
1675E - Replace With the Previous Minimize
839A - Arya and Bran
16B - Burglar and Matches
1625B - Elementary Particles
1725G - Garage
1725B - Basketball Together
735A - Ostap and Grasshopper
1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU